import Mock from 'mockjs'
import qs from 'qs'

Mock.setup({
  timeout: '500-1000',
})

Mock.mock(/\/goods\/test/, 'get', (config) => {
  // 根据传入的参数 里面的pageSize的多少来决定 显示多少个数据
  console.log(config.url)
  const queryString = config.url.split('?')[1]
  const queryObject = qs.parse(queryString)
  const category = []
  for (let i = 0; i < queryObject.pageSize; i++) {
    // 二级分类
    let bxMallSubDto = []
    for (let j = 0; j < queryObject.pageSize; j++) {
      bxMallSubDto.push(
        Mock.mock({
          mallSubId: '@id',
          mallCategoryId: '@id',
          mallSubName: '@cname',
          comments: '@cname',
        })
      )
    }
    category.push(
      Mock.mock({
        mallCategoryId: '@id',
        mallCategoryName: '@name',
        bxMallSubDto: bxMallSubDto,
        comment: '@cname(4)',
        image: `@image('50x50')`,
        // bxMallSubDto: '@ctitle(2, 10)',
        // float(100, 200, 3, 5) // 表示 小数点有 3 - 5 位数； 2 2 表示只有2位数
        // price: '@float(100, 200, 3, 5)',
        // mallPrice: '@float(100, 200, 3, 5)',
        // image: `@image('200x100')`
      })
    )
  }

  // 轮播图
  let sliders = []
  for (let j = 0; j < queryObject.pageSize; j++) {
    sliders.push(
      Mock.mock({
        id: '@id',
        imageUrl: `@image('400x150')`,
      })
    )
  }

  // 推荐商品
  let recommendGoods = []
  for (let j = 0; j < queryObject.pageSize; j++) {
    recommendGoods.push(
      Mock.mock({
        goodsId: '@id',
        image: `@image('90x90')`,
        goodsName: `@cname(4)`,
        price: `@float(0, 500, 2, 2)`,
        mallPrice: `@float(0, 500, 2, 2)`,
      })
    )
  }
  // 楼层数据
  let floor1 = [
    {
      goodsId: 'e53c046465204d4fb8f22431cc2807e7',
      image:
        'http://images.baixingliangfan.cn/homeFloor/20180407/20180407180109_6316.jpg',
    },
    {
      goodsId: 'f36f6dd8f62247d5846eaa9b3f269cbc',
      image:
        'http://images.baixingliangfan.cn/homeFloor/20180407/20180407180151_6180.jpg',
    },
    {
      goodsId: '72a3ec63956347a2a9f113589fe79c03',
      image:
        'http://images.baixingliangfan.cn/homeFloor/20180407/20180407180217_3970.jpg',
    },
    {
      goodsId: 'a632bfb3818541da8e6843d6d0dbd917',
      image:
        'http://images.baixingliangfan.cn/homeFloor/20180407/20180407180257_2378.jpg',
    },
    {
      goodsId: '6694401a30a940f6ae437d541b7fd26d',
      image:
        'http://images.baixingliangfan.cn/homeFloor/20180407/20180407180427_8557.jpg',
    },
  ]

  // 热卖商品
  let hotGoods = [
    {
      mallPrice: 3.9,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415120500_6504.jpg',
      goodsId: 'fb0f913950944b66a97ae262ad14609a',
      price: 3.9,
      name: '美汁源果粒奶优水果饮料蜜桃450ml/瓶',
    },
    {
      mallPrice: 4.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415115202_8432.jpg',
      goodsId: '775e575ce28a4f89b1dfe2c99eb08ae7',
      price: 4.5,
      name: '阿华田麦芽乳饮品牛奶味250mL/盒',
    },
    {
      mallPrice: 3.7,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415121351_6470.jpg',
      goodsId: 'e68d5293c0a04e99a3480aaaad101362',
      price: 3.7,
      name: '养元香浓六个核桃240ml/瓶',
    },
    {
      mallPrice: 6.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415120956_8491.jpg',
      goodsId: '7c377350cc9342edba600f3f6a548bd0',
      price: 6.5,
      name: '名屋木瓜牛乳340ml/瓶',
    },
    {
      mallPrice: 3.9,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415120411_5740.jpg',
      goodsId: 'f8c3f62810aa4ce781d14a885333a2b8',
      price: 3.9,
      name: '美汁源果粒奶优草莓味450ml/瓶',
    },
    {
      mallPrice: 7.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415120720_7233.jpg',
      goodsId: '85d4fece907a4170b4b27a22c035321d',
      price: 7.5,
      name: '名屋醇豆浆饮料485ml/瓶',
    },
    {
      mallPrice: 5.0,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180103161335_9324.jpg',
      goodsId: '9abd33f0d2e4496f9c023a1dcfbfe2ad',
      price: 6.3,
      name: '李子园甜牛奶乳饮料450ml/瓶',
    },
    {
      mallPrice: 5.0,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415120239_7917.jpg',
      goodsId: '1258c2fd52844f679fad1ebf24764082',
      price: 5.0,
      name: '李子园草莓风味乳饮料450ml/瓶',
    },
    {
      mallPrice: 6.3,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20171224082006_6602.jpg',
      goodsId: 'bd25fd5d128e41fd9a737e99f75f92f8',
      price: 8.5,
      name: '娃哈哈AD钙奶220ml*4/条',
    },
    {
      mallPrice: 6.0,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415121537_4372.jpg',
      goodsId: 'cfbe6ec3101a414f9563a8c6624aec08',
      price: 6.0,
      name: '一榨鲜绿豆汁300ml/瓶',
    },
    {
      mallPrice: 5.0,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415120109_275.jpg',
      goodsId: 'e9808eb0d3574c11971e38f75076f1a4',
      price: 5.0,
      name: '李子园朱古力风味乳饮料450ml/瓶',
    },
    {
      mallPrice: 7.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415120857_4885.jpg',
      goodsId: 'a5d1130de39f434facc6d35514cea053',
      price: 7.5,
      name: '名屋黑豆浆饮料485ml/瓶',
    },
    {
      mallPrice: 4.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415114959_7217.jpg',
      goodsId: '06130c91497b4806bf2b3e538814bb66',
      price: 4.5,
      name: '阿华田麦芽乳饮品高钙味250mL/盒',
    },
    {
      mallPrice: 6.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415121108_2001.jpg',
      goodsId: 'b75e437adc0540c6b30516537d759122',
      price: 6.5,
      name: '名屋香蕉牛乳340ml/瓶',
    },
    {
      mallPrice: 3.9,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415120608_2319.jpg',
      goodsId: '0d51d2863bdc485688c2fee2a165bb51',
      price: 3.9,
      name: '美汁源果粒奶优原味450ml/瓶',
    },
    {
      mallPrice: 7.4,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20171224082144_8430.jpg',
      goodsId: '85173b3ce7a24a44ac2ed960a3e431fc',
      price: 9.0,
      name: '旺仔牛奶125ml*4/条',
    },
    {
      mallPrice: 68.0,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415122117_1031.jpg',
      goodsId: '99e37959ae22433da7bb378a2d24c19c',
      price: 68.0,
      name: '同福阿胶粥300g/箱',
    },
    {
      mallPrice: 3.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415122256_2373.jpg',
      goodsId: '068fe09cf2a849b4b8c7ce3fea734072',
      price: 3.5,
      name: '银鹭桂圆莲子八宝粥360g/瓶',
    },
    {
      mallPrice: 14.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415121432_880.jpg',
      goodsId: '8172961149434b51865612820c7b8891',
      price: 14.5,
      name: '椰树牌椰汁饮料1L/瓶',
    },
    {
      mallPrice: 4.5,
      image:
        'http://images.baixingliangfan.cn/compressedPic/20180415115515_7254.jpg',
      goodsId: 'a870459dfbba4df8af52e52aa6d0c426',
      price: 4.5,
      name: '豆本豆原味豆奶250ml/盒',
    },
  ]
  return {
    msg: '获取足迹成功',
    result: {
      advertiseImage: Mock.mock(`@image('350x200')`),
      counts: 20,
      pageSize: queryObject.pageSize,
      page: queryObject.page,
      category: category,
      sliders: sliders,
      recommendGoods: recommendGoods,
      floor1: floor1,
      floor_title: '楼层商品',
      hotGoods,
    },
  }
})
